<?php
class ChannelService {
    private $db = null;
    function __construct(){
        $this->db = Database::GetDataBaseObj();
    }

    public function getAllChannel(){
        $query = "select * from tbl_channel ORDER BY Title ASC";
        return $this->db->GetManyRows($query);
    }
	
	public function getAllChannelType2(){
		$query = "select * "
				 . "from zoovision.tbl_channel a inner join zoovision.tbl_server b "
				 . "on a.Id = b.ChannelId " 
				 . "where a.ChannelType = 2";
		return $this->db->GetManyRows($query);
	}
	
	public function getChannelByVideoId($videoId){
		$query= "select * from zoovision.tbl_channel a inner join zoovision.tbl_server b
					on a.Id = b.ChannelId
				 where a.ChannelType = 2 and b.id = ".$videoId;
		return $this->db->GetOneRow($query);
	}
	
	public function getVideoById($id){
		$query="select * from zoovision.tbl_server where id=".$id;
		return $this->db->GetOneRow($query);
	}

    public  function getChannelServers($id){
        $query = "select * from tbl_server where ChannelId = ".$id;
        if($id==15){
            $query = $query." ORDER BY Id DESC";
        }
        return $this->db->GetManyRows($query);
    }
    public function channels(){
        $channels = $this::getAllChannel();
        $result = array();
        foreach($channels as &$channel){
            $channel["Servers"] = $this::getChannelServers($channel["Id"]);
            $result[] = $channel;
        }
        return $result;
    }

    public function insertServer($cId,$ServerName,$link){
        $query = "INSERT INTO tbl_server(ChannelId,Name,Link,isLive) VALUES ($cId,'$ServerName','$link',1)";
        return $this->db->Insert($query);
    }
}
?>